package com.study.design.pattern.pattern.behavioral.observer.java;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 * @Author: gongsl
 * @Date: 2025-03-23 22:49
 * @description: 被观察者 - WeatherStation（天气站）
 */
public class WeatherStation {
    private double temperature;
    private PropertyChangeSupport support;

    public WeatherStation() {
        support = new PropertyChangeSupport(this);
    }

    public double getTemperature() {
        return temperature;
    }

    public void setTemperature(double temperature) {
        double oldTemp = this.temperature;
        this.temperature = temperature;
        support.firePropertyChange("temperature", oldTemp, temperature);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        support.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        support.removePropertyChangeListener(listener);
    }
}
